import 'package:equatable/equatable.dart';

class User extends Equatable {
  const User(
      {this.appId = '',
      this.version = '',
      this.name = '',
      this.password = '',
      this.author = '',
      this.start = 0,
      this.expired = 0});

  User.create(
      {this.appId = '',
      this.version = '',
      this.name = '',
      this.password = '',
      this.author = '',
      this.expired = 0})
      : start = DateTime.now().millisecondsSinceEpoch;

  ///应用唯一ID
  final String appId;

  ///应用唯一版本
  final String version;

  ///应用作者
  final String author;

  ///用户名
  final String name;

  ///用户密码,MD5加密后的
  final String password;

  ///起始日期
  final int start;

  ///到期日
  ///
  /// -1 : 永久使用,不限版本
  /// 0 : 永久使用该版本及之前
  /// 1 : 限时使用,不限版本
  final int expired;

  Map getUserData() => {
        "appId": appId,
        "version": version,
        "name": name,
        "author": author,
        "password": "",
        "start": start,
        "expired": expired
      };

  User? getUser(Map json) {
    try {
      return User(
        appId: json['appId'] as String,
        version: json['version'] as String,
        name: json['name'] as String,
        author: json['author'] as String,
        password: json['password'] as String,
        start: json['start'] as int,
        expired: json['expired'] as int,
      );
    } catch (e) {
      return null;
    }
  }

  ///根据当前系统时间获取过期时间,以毫秒记
  // int getExpired(){
  //   return 0;
  // }

  ///加密
  void encryption() {}

  ///解密
  void decryption() {}

  @override
  List<Object> get props =>
      [appId, version, name, author, password, start, expired];
}
